package com.filmbooks.presenter.book;

import com.filmbooks.contract.book.BookDeatilContract;
import com.filmbooks.model.book.BookDetailModel;
import com.filmbooks.model.home.bean.book.BookDetailBean;
import com.filmbooks.model.home.bean.book.BookItemBean;

import io.reactivex.functions.Consumer;

/**
 * Created by heshuxiang on 2018/3/9.
 * 描述：
 * 公司：盟将威
 * 作者：heshuxiang
 * 日期：2018/3/9.
 * 工程：FilmBooks
 * 包：com.filmbooks.presenter.book
 */

public class BookDetailPresenter extends BookDeatilContract.BookDetailPresenter {
    @Override
    public BookDeatilContract.IBookDetailModel getModel() {
        return BookDetailModel.newInstance();
    }

    public static BookDetailPresenter newInstance() {
        return new BookDetailPresenter();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void loadBookDetail(String id) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.getBookDetail(id).subscribe(new Consumer<BookDetailBean>() {
            @Override
            public void accept(BookDetailBean bean) throws Exception {
                if (mIView == null)
                    return;

                mIView.showBookDetail(bean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                if (mIView == null)
                    return;
                mIView.showToast("Network error.");
                mIView.showNetworkError();
            }
        }));
    }

    @Override
    public void onHeaderClick(BookItemBean bean) {

    }

}
